package com.visualexpress.shards;

import java.util.List;

import org.hibernate.shards.ShardId;
import org.hibernate.shards.cfg.ShardConfiguration;
import org.hibernate.shards.loadbalance.RoundRobinShardLoadBalancer;
import org.hibernate.shards.strategy.ShardStrategy;
import org.hibernate.shards.strategy.ShardStrategyFactory;
import org.hibernate.shards.strategy.ShardStrategyImpl;
import org.hibernate.shards.strategy.access.SequentialShardAccessStrategy;
import org.hibernate.shards.strategy.access.ShardAccessStrategy;
import org.hibernate.shards.strategy.resolution.AllShardsShardResolutionStrategy;
import org.hibernate.shards.strategy.resolution.ShardResolutionStrategy;
import org.hibernate.shards.strategy.selection.RoundRobinShardSelectionStrategy;
import org.hibernate.shards.strategy.selection.ShardSelectionStrategy;

import com.visualexpress.domain.Site;



public  class SpecifiedSiteShardStrategyFactory  extends VEShardStrategyFactory {
	ShardSelectionStrategy selectionStrategy;

	ShardId shardId;
	
	

	public SpecifiedSiteShardStrategyFactory(ShardId shardId) {
		super();
		this.shardId = shardId;
	}

	public ShardSelectionStrategy getSelectionStrategy(List<ShardId> shardIds) {
		 if(selectionStrategy ==null)
			 selectionStrategy = new SpecifiedSiteSelectionStrategy(shardId);
		 return selectionStrategy;
	}



	class SpecifiedSiteSelectionStrategy implements ShardSelectionStrategy {
		ShardId shardId;
		
		public SpecifiedSiteSelectionStrategy(ShardId shardId) {
			super();
			this.shardId = shardId;
		}

		@Override
		public ShardId selectShardIdForNewObject(Object obj) {
			return this.shardId;
		}
	
	}



	
}
